package com.bdqn.xiangchuan.dao;




import com.bdqn.xiangchuan.base.Gcmc;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;


public interface GcmcDao {
	@Select("SELECT gcmc_id,gcmc_name,khmc_id FROM gcmc")
	public List<Gcmc> getAll();
	
	@Select("SELECT gcmc_id,gcmc_name,khmc_id FROM gcmc WHERE khmc_id = #{khmc_id}")
	public List<Gcmc> getGcmcsByKhId(@RequestParam("khmc_id") int khmc_id);
	
	@Insert("insert into crk5.gcmc (gcmc_name, khmc_id)values(#{gcmc_name}, #{khmc_id});")
	public int add(Gcmc gcmc);
	
	@Update("UPDATE crk5.gcmc gcmc_name = #{gcmc_name} , khmc_id = #{khmc_id} where gcmc_id = #{gcmc_id} ;")
	public int update(Gcmc gcmc);
	
	@Delete("<script>"+
	            "DELETE FROM crk5.gcmc WHERE gcmc_id IN" +
	            "<foreach collection='list' open='(' item='id' separator=',' close=')'> #{id}" +
	            "</foreach>" +
	            "</script>")
	public int delete(List<Integer> gcmc_ids);	
	@Select("SELECT gcmc_id,gcmc_name,khmc_id FROM gcmc gcmc_name like %#{gcmc_name}%")
	public List<Gcmc> getGcmcByGcName(String gcmc_name);
}
